#include "stooge.h"

int linecmp(int *line1, int *line2)
{
    int a='a',b='b';
    
    while(a!='\n' && b!='\n'){
        a = *line1++;
        b = *line2++;
        if(a < b) return -1; // line1 es menor
        else if (a > b) return 1; // line2 es menor
    }

    // son iguales
    if(a=='\n' && b =='\n'){
        return 0;
    }
    
    // line1 es menor
    if(a=='\n') return -1;

    // line2 es menor
    return 1;
} 

void stoogesort(int **lines, unsigned int i, unsigned int j) {
    
	int k;
	int *temp;

	if (linecmp(lines[i],lines [j]) > 0) {
		temp = lines[i];
		lines[i] = lines[j];
		lines[j] = temp;
	}

	if ((i+1)>=j) return;

	k = (int) ((j-i+1)/3);
	stoogesort(lines, i, j-k);
	stoogesort(lines, i+k, j);
	stoogesort(lines, i, j-k);
}

void sort(void *array, unsigned int i, unsigned int j);
